﻿using MYQQX.SP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MYQQX
{
    public partial class ShowXyForm : Form
    {
        private CardGroup _group;
        public bool NeedChose = false;
        internal CheckSpDelegate CheckSpAct;

        public ISp choseSp { get; private set; }

        public ShowXyForm(CardGroup Group)
        {
            _group = Group;
            InitializeComponent();
        }

        private void ShowXyForm_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < _group.spList.Count; i++)
            {
                var card = _group.spList[i];

                if (CheckSpAct != null && !CheckSpAct.Invoke(card.CardName))
                    continue;

                Label label = new Label();
                label.Text = " [" + card.Name + "]";
                label.AutoSize = false;
                label.Width = 180;
                label.Height = 20;
                label.TextAlign = ContentAlignment.MiddleLeft;
                label.Tag = card;
                label.BackColor = Color.Pink;
                label.Click += card_click;

                var y = i / 3;
                var x = i % 3;

                label.Location = new Point(5 + x * 200, 5 + y * 25);

                pnlXY.Controls.Add(label);
            }
        }

        private void card_click(object sender, EventArgs e)
        {
            var label = sender as Label;
            var sp = label.Tag as ISp;

            lblName.Text = $"[{sp.Name}][{sp.SpScore + 2}分]";
            lblDesc.Text = sp.Desc;

            choseSp = sp;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (NeedChose && choseSp == null)
            {
                MessageBox.Show("请选择一张稀有牌！");
                return;
            }

            this.DialogResult = DialogResult.OK;
        }

        private void ShowXyForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (NeedChose && choseSp == null)
            {
                MessageBox.Show("请选择一张稀有牌！");
                e.Cancel = true;
            }
        }
    }
}
